package sis.studentinfo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static sis.studentinfo.DateUtil.createDate;

import java.util.Date;

import org.junit.Before;
import org.junit.Test;
abstract public class SessionTest {
	private Session session;
	private Date startDate;
	public static final int CREDITS = 3;
	
	@Before
	public void setUp(){
		startDate = createDate(2003, 1, 6);
		session = createSession(new Course("ENGL","101"), startDate);
		session.setNumberOfCredits(CREDITS);
	}
	abstract protected Session createSession(
			Course course, Date startDate);
	
	@Test
	public void testCreate() {
		assertEquals("ENGL", session.getDepartment());
		assertEquals("101", session.getNumber());
		assertEquals(0, session.getNumberOfStudents());
	}
	
	@Test
	public void testEnrollStudents() {

		Student student1 = new Student("Cain Divoe");
		session.enroll(student1);
		assertEquals(1, session.getNumberOfStudents());
		assertEquals(CREDITS, student1.getCredits());
		assertEquals(student1, session.get(0));

		Student student2 = new Student("Coralee Davauhgn");
		session.enroll(student2);
		assertEquals(2, session.getNumberOfStudents());
		assertEquals(CREDITS, student2.getCredits());
		assertEquals(student1, session.get(0));
		assertEquals(student2, session.get(1));
	}
	
	@Test
	public void testComparable(){
		final Date date =  new Date();
		CourseSession sessionA = CourseSession.create(new Course("CMSC", "101"), date);
		CourseSession sessionB = CourseSession.create(new Course("ENGL", "101"), date);
		assertTrue(sessionA.compareTo(sessionB) < 0);
		assertTrue(sessionB.compareTo(sessionA) > 0);
		
		CourseSession sessionC = CourseSession.create(new Course("CMSC", "101"), date);
		assertEquals(0,sessionA.compareTo(sessionC));
		
		CourseSession sessionD = CourseSession.create(new Course("CMSC", "210"), date);
		assertTrue(sessionD.compareTo(sessionC) > 0);
		assertTrue(sessionC.compareTo(sessionD) < 0);
		
	}
}
